const mongoConnected = require("../lib/mongoose_connect");
const mongoModels = require("../lib/mongoose_schemas");
const lodash = require("lodash");
const fs = require("fs-extra");
const path = require("path");
const THREE = require("three");
const DATA = require("../test/210221_yulinplayers.json");
const DATA2 = require("../test/210223_inzone-gaoshou-2.json");

let chengnei = DATA2.filter(e => e.is_in_zone)
debugger
return
mongoConnected.then(async $ => {


  let gaoshous = DATA.filter(e => {
    return e.matches_count >= 10 && e.qianwulv >= 0.45
  });
  console.log(gaoshous.length, "个高手")
  let luodians = (await mongoModels.TB21_luodian.find({
    "map_name": "Savage_Main"
  }, {
    _id: 0
    // is_gaoshou:
  })).map(e => e._doc);
  debugger
  luodians.forEach(e => {
    e.is_gaoshou = Number(gaoshous.findIndex(g => g.player_name === e.player_name) >= 0)
  })
  debugger
  await fs.writeFile(path.join(__dirname, "../test/210223_inzone-gaoshou-2.json"), JSON.stringify(luodians));


  return
  let zones = (await mongoModels.TB21_city.find());
  // debugger
  luodians = (await mongoModels.TB21_luodian.find({
    "map_name": "Savage_Main"
  }));
  for (let luodian of luodians) {
    let me = new THREE.Vector3(luodian.luodian.x, luodian.luodian.y, 0);
    let dis = {
      'a': Infinity,
      'b': Infinity,
      'c': Infinity,
      'd': Infinity
    }
    let is_in_zone = false;
    for (let zone of zones) {
      let zoneCenter = new THREE.Vector3(lodash.mean(zone.extent.x), lodash.mean(zone.extent.y), 0);
      let dist = me.distanceTo(zoneCenter);
      if (dist < dis[zone.city_type]) {
        dis[zone.city_type] = dist;
      }
    }
    if (luodian._doc.dev0223.zone.length) {
      let inZone = zones.find(z => z.name_id === luodian._doc.dev0223.zone[0]);
      dis[inZone.city_type] = 0;
      is_in_zone = true;
    }
    await luodian.update({
      $set: {
        is_in_zone: is_in_zone,
        distance_to_city_type_a: dis['a'],
        distance_to_city_type_b: dis['b'],
        distance_to_city_type_c: dis['c'],
        distance_to_city_type_d: dis['d'],
      }
    })
    // debugger
  }
  debugger
  return
  for (let luodian of luodians) {
    let evLand = await mongoModels.Event.findOne({
      match_id: luodian.match_id,
      _T: "LogParachuteLanding",
      "character.accountId": luodian.account_id
    });
    await luodian.update({
      $set: {
        "dev0223": {
          LogParachuteLanding_distance: evLand._doc.distance,
          zone: evLand._doc.character.zone
        }
      }
    })
    // debugger
  }
  debugger

})